﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using Gallio.Framework;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using System.Configuration;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;
using System.IO;
using System.Reflection;




namespace DotNetNuke.Tests.UI.WatiN.HostTests
{
    [TestFixture]
    
    public class HostSettingsTests : HTBase
    {
        #region Test Setup and TearDown

        [SetUp]
        public void SetUp()
        {
            
            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {
            TearDownTest();
        }

        #endregion

        #region Tests


        [Test]
        public void Update_Host_Email()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            //Act
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.UpdateLink.ClickNoWait();

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            Assert.IsTrue(hostSettings.HostEmailTextField.Text.CompareTo("test@dnn.com") == 0);
        }

        [Test]
        public void Changing_Host_Title()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            //Act
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            hostSettings.HostTitleTextField.Value = "Test Title";
            hostSettings.UpdateLink.ClickNoWait();

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            Assert.IsTrue(hostSettings.HostTitleTextField.Text.CompareTo("Test Title") == 0);

        }

        [Test]
        public void Changing_Host_URL()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            //Act
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            hostSettings.HostURLTextField.Value = "http://www.testurl.com";
            hostSettings.UpdateLink.ClickNoWait();

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            Assert.AreEqual(@"http://www.testurl.com", hostSettings.HostURLTextField.Text);

        }

        [Test]
        public void Enabling_Disabling_Users_Online()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            HostUserPage hostAccountsPage = new HostUserPage(homePage);
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            //Assert
            Assert.IsFalse(hostAccountsPage.UserGridContainsUserOnlineImage());

            //Act
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.UpdateLink.Click();
            System.Threading.Thread.Sleep(2000);

            hostSettings.OtherSettingsTab.Click();
            hostSettings.EnableUsersOnlineCheckBox.Checked = true;
            hostSettings.UpdateLink.Click();
            System.Threading.Thread.Sleep(1500);

            //Assert
            ieInstance.GoTo(SiteURL + "/tabid/34/portalid/0/Default.aspx");
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(hostAccountsPage.UserGridContainsUserOnlineImage());
        }

        [Test]
        public void Entering_Auto_Unlock_Accounts_Value()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            UserPage userPage = new UserPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1500);
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            //Act
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);

            hostSettings.OtherSettingsTab.ClickNoWait();
            hostSettings.AutoUnlockAccountsTime.Value = "2";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);

            loginPage.LogoffUser();
            for (int i = 0; i < 6; i++)
            {
                //Click the Login/Logout button
                loginPage.LoginLink.Click();
                //Enter the users information
                loginPage.UserName.Value = TestUsers.User1.UserName;
                loginPage.Password.Value = "wrong";
                //Click the Login Button
                loginPage.LoginButton.Click();
            }
            //Assert
            Assert.IsTrue(loginPage.ErrorMsg.Text.Contains("This account has been locked out"));
            System.Threading.Thread.Sleep(120000);

            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            Assert.AreEqual(TestUsers.User1.DisplayName, baseWatinObject.RegisterLink.Text);
        }

        [Test]
        public void Removing_Adding_File_Upload_Extensions()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            FileManagerPage fileManager = new FileManagerPage(homePage);

            //Act
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);

            hostSettings.OtherSettingsTab.Click();
            hostSettings.AllowableFileExtensions.Value = "swf,jpg";
            hostSettings.UpdateLink.ClickNoWait();

            System.Threading.Thread.Sleep(1500);
            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            fileManager.UploadFile(TestEnvironment.FilePath);

            //Assert
            Assert.IsTrue(fileManager.UploadMessage.Text.Contains("A Restricted File Type"));

            //Act
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            hostSettings.OtherSettingsTab.Click();
            hostSettings.AllowableFileExtensions.Value = "swf,jpg,txt";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);

            ieInstance.GoTo(SiteURL + "/Admin/FileManager.aspx");
            fileManager.UploadFile(TestEnvironment.FilePath);

            //Assert
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(homePage.ModuleTitleSpans.Count == 1);
            Assert.AreEqual("File Upload", fileManager.ModuleTitleSpan.Text);
            Assert.IsTrue(fileManager.UploadMessage.Text.Contains("Uploaded Successfully"));
        }

        [Test]
        public void Clicking_Go_To_Payment_Processor_Website()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            //Act
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            hostSettings.PaymentOptionsExpandLink.ClickNoWait();
            hostSettings.PaymentOptionsSelectList.Select("PayPal");
            hostSettings.GoToPaymentProcessorLink.Click();
            System.Threading.Thread.Sleep(5000);
            IE popUp =  IE.AttachTo<IE>(Find.ByUrl(s => s.StartsWith("https://www.paypal.com")));

            //Assert
            Assert.IsTrue(popUp.Url.Contains("www.paypal.com"));
            Assert.IsTrue(popUp.Title.Contains("PayPal"));
            popUp.Close();
        }

        [Test]
        public void Changing_Help_URL()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;

            //Act
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            hostSettings.OtherSettingsTab.Click();
            hostSettings.HelpUrlField.Value = "www.facebook.com";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.HelpLink.Click();
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.HelpLink.Click();
            }
            System.Threading.Thread.Sleep(5000);
            IE popUpWindow = IE.AttachTo<IE>(Find.ByUrl(s => s.StartsWith("http://www.facebook.com")));
            
            Assert.IsTrue(popUpWindow.Title.Contains("Facebook"));
            popUpWindow.Close();
        }

        [Test]
        public void Changing_the_Site_Payment_Settings()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            //Act
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            hostSettings.PaymentOptionsExpandLink.ClickNoWait();
            hostSettings.PaymentOptionsSelectList.Select("PayPal");
            hostSettings.ProcessorUserIdField.Value = TestUsers.PaymentUser.UserName;
            hostSettings.ProcessorPasswordField.Value = TestUsers.PaymentUser.Password;
            hostSettings.HostingCurrencySelectList.Select("Euros (EUR)");
            hostSettings.UpdateLink.ClickNoWait();

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            hostSettings.PaymentOptionsExpandLink.Click();
            Assert.IsTrue(hostSettings.PaymentOptionsSelectList.SelectedItem.Equals("PayPal"));
            Assert.IsTrue(hostSettings.ProcessorUserIdField.Text.Equals(TestUsers.PaymentUser.UserName));
            Assert.IsTrue(hostSettings.ProcessorPasswordField.Text.Equals(TestUsers.PaymentUser.Password));
            Assert.IsTrue(hostSettings.HostingCurrencySelectList.SelectedItem.Equals("Euros (EUR)"));
            
        }

        [Test]
        public void Updating_Control_Panel_Style()
        {
            //Arrange
            bool usesRibbonBar = false;
            bool usesClassic = false;
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            usesClassic = !ieInstance.Element(Find.ByClass("ControlPanel")).Exists;
           
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                usesRibbonBar = true;
            }
            
            //Act & Assert
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            hostSettings.OtherSettingsTab.ClickNoWait();
            SelectList controlPanel = hostSettings.ControlPanelStyleSelectList;
            if (controlPanel.Options.Count == 2)
            {
                //Only 2 options are available
                if (usesRibbonBar)
                {
                    //Select the Iconbar
                    hostSettings.UpdateControlPanelStyle("ICONBAR");
                    Assert.IsTrue(homePage.ControlPanelElement.Id.Contains("_IconBar.ascx"));
                    
                    //Select the Ribbonbar again
                    hostSettings.UpdateControlPanelStyle("RIBBONBAR");
                    Assert.IsTrue(homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID));
                }
                else
                {                 
                    //Select the Ribbonbar
                    hostSettings.UpdateControlPanelStyle("RIBBONBAR");
                    Assert.IsTrue(homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID));

                    //Select the Iconbar again
                    hostSettings.UpdateControlPanelStyle("ICONBAR");
                    Assert.IsTrue(homePage.ControlPanelElement.Id.Contains("dnn_IconBar.ascx"));
                    
                }
            }
            else if (controlPanel.Options.Count == 3)
            {
                //3 options are available
                if (usesClassic)
                {
                    //Select the Ribbonbar
                    hostSettings.UpdateControlPanelStyle("RIBBONBAR");
                    Assert.IsTrue(homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID));

                    //Select the Iconbar 
                    hostSettings.UpdateControlPanelStyle("ICONBAR");
                    Assert.IsTrue(homePage.ControlPanelElement.Id.Contains("dnn_IconBar.ascx"));
                    

                    //Select the Classic Bar again
                    hostSettings.UpdateControlPanelToClassic();
                    Assert.IsTrue(ieInstance.Div(Find.ById("dnn_ControlPanel")).Exists);

                }
                else if (usesRibbonBar)
                {
                    //Select the Iconbar 
                    hostSettings.UpdateControlPanelStyle("ICONBAR");
                    Assert.IsTrue(homePage.ControlPanelElement.Id.Contains("dnn_IconBar.ascx"));
                    
                    //Select the Classic Bar
                    hostSettings.UpdateControlPanelToClassic();
                    Assert.IsTrue(ieInstance.Div(Find.ById("dnn_ControlPanel")).Exists);

                    //Select the Ribbonbar again
                    hostSettings.UpdateControlPanelStyle("RIBBONBAR");
                    Assert.IsTrue(homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID));
                }
                else{
                    //Select the Classic Bar
                    hostSettings.UpdateControlPanelToClassic();
                    Assert.IsTrue(ieInstance.Div(Find.ById("dnn_ControlPanel")).Exists);

                    //Select the Ribbonbar
                    hostSettings.UpdateControlPanelStyle("RIBBONBAR");
                    Assert.IsTrue(homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID));

                    //Select the Iconbar again 
                    hostSettings.UpdateControlPanelStyle("ICONBAR");
                    Assert.IsTrue(homePage.ControlPanelElement.Id.Contains("dnn_IconBar.ascx"));
                                   
                }
            }
        }

        [Test]
        public void Select_New_Host_Portal()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
           
            //Create a portal for testing
            ieInstance.GoTo(SiteURL + "/Host/Portals.aspx");
            HostPortalPage portalPage = new HostPortalPage(homePage);
            portalPage.AddChildPortal(ApplicationName, "Test Portal", "TestPortal");
            System.Threading.Thread.Sleep(1500);

            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            //Act
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            hostSettings.HostPortalSelectList.Select("Test Portal");
            hostSettings.UpdateLink.ClickNoWait();

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            Assert.IsTrue(hostSettings.HostPortalSelectList.SelectedItem.Equals("Test Portal"));
            //Clean up portal folders
            Directory.Delete(PhysicalPath + @"\testportal", true);
            Directory.Delete(PhysicalPath + @"\Portals\1", true);
        }

        [Test]
        public void Change_Site_Log_History()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Create a portal for testing
            ieInstance.GoTo(SiteURL + "/Host/Portals.aspx");
            HostPortalPage portalPage = new HostPortalPage(homePage);
            portalPage.AddChildPortal(ApplicationName, "Test Portal 1", "TestPortal1");
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            
            //Assert
            AdminSiteLogPage siteLog = new AdminSiteLogPage(homePage);            
            ieInstance.GoTo(SiteURL + "/testportal1/Admin/SiteLog.aspx");
            Assert.IsTrue(siteLog.ModuleMessageSpan.Text.Contains("Your Hosting Provider Has Disabled"));

            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            //Act
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            hostSettings.OtherSettingsTab.ClickNoWait();
            hostSettings.SiteLogHistoryField.Value = "15";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Create a second portal
            ieInstance.GoTo(SiteURL + "/Host/Portals.aspx");
            portalPage.AddChildPortalDontClickMsgLink(ApplicationName, "Test Portal 2", "TestPortal2");
            System.Threading.Thread.Sleep(1500);
            //portalPage.AddChildPortal(ApplicationName, "Test Portal 2", "TestPortal2");
            ieInstance.GoTo(SiteURL + "/Home.aspx");

            //Assert
            System.Threading.Thread.Sleep(1500);
            ieInstance.GoTo(SiteURL + "/testportal2/Admin/SiteLog.aspx");
            Assert.IsTrue(siteLog.MessageSpan.Text.Contains("Has Limited Your Portal To 15 Days"));

            System.Threading.Thread.Sleep(1500);
            ieInstance.GoTo(SiteURL + "/testportal1/Admin/SiteLog.aspx");
            Assert.IsTrue(siteLog.MessageSpan.Text.Contains("Your Hosting Provider Has Disabled"));

            //Clean up portal folders
            Directory.Delete(PhysicalPath + @"\testportal1", true);
            Directory.Delete(PhysicalPath + @"\Portals\1", true);
            Directory.Delete(PhysicalPath + @"\testportal2", true);
            Directory.Delete(PhysicalPath + @"\Portals\2", true);
        }
        
       [Test]
        public void Enable_Disable_Remember_Me()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginLink.Click();

            //Assert that the remember me box is currently enabled
            Assert.IsTrue(loginPage.RememberMeCheckBox.Exists);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);

            //Act
            hostSettings.EnableRememberMeCheckbox.ClickNoWait();
            //Need to enter a valid EmailAddress so the checkbox value is saved correctly
            hostSettings.HostEmailTextField.Value = "test@dnn.com";
            hostSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(5000);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginLink.ClickNoWait();

            //Assert
            Assert.IsFalse(loginPage.RememberMeCheckBox.Exists);
        }

       [Test]
       public void Enabling_Disabling_Module_Online_Help()
       {
           //Arrange
           WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
           LoginPage loginPage = new LoginPage(homePage);
           loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
           bool usesRibbonBar = false;

           //Add a page to the website
           String pageName = "Test Page";
           ControlPanel controlPanel = null;
           RibbonBar ribbonBar = null;

           if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
           {
               ribbonBar = new RibbonBar(homePage);
               ribbonBar.NewPageLink.Click();
               usesRibbonBar = true;
           }
           else
           {
               controlPanel = new ControlPanel(homePage);
               controlPanel.AddPageLink.Click();
           }
           PageSettingsPage newPage = new PageSettingsPage(homePage);
           newPage.PageNameField.Value = pageName;
           newPage.PageTemplateSelect.Select("None Specified");
           newPage.AllUsersViewPermissionCheckbox.ClickNoWait();
           newPage.AddPageLink.ClickNoWait();
           System.Threading.Thread.Sleep(2000);
           ieInstance.GoTo(SiteURL + "/testpage.aspx");

           //Add an HTML module to the page
           string moduleContent = "This is a test module. ";
           if (!usesRibbonBar)
           {
               if (VersionType.CompareTo("Community") == 0)
               {
                   controlPanel.AddHTMLModuleToPageWithContent("Test Module", "HTML", moduleContent, 0);
               }
               else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
               {
                   controlPanel.AddHTMLModuleToPageWithContent("Test Module", "HTML Pro", moduleContent, 0);
               }
           }
           else
           {
               if (VersionType.CompareTo("Community") == 0)
               {
                   ribbonBar.AddHTMLModuleToPageWithContent("Test Module", "HTML", moduleContent, 0);

               }
               else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
               {
                   ribbonBar.AddHTMLModuleToPageWithContent("Test Module", "HTML Pro", moduleContent, 0);

               }
           }
           System.Threading.Thread.Sleep(1500);
           ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
           HostSettingsPage hostSettings = new HostSettingsPage(homePage);

           //Act
           hostSettings.EnableModuleOnlineHelpCheckbox.Checked = false;
           hostSettings.HostEmailTextField.Value = "test@dnn.com";
           hostSettings.UpdateLink.Click();
           System.Threading.Thread.Sleep(1000);
           ieInstance.GoTo(SiteURL + "/testpage.aspx");
           System.Threading.Thread.Sleep(1500);

           //Assert
           ModulePage modulePage = new ModulePage(homePage);
           //modulePage.ModuleActionMenuImage.FireEvent("onmouseover");
           Assert.IsFalse(modulePage.ModuleOnlineHelpLink.Exists);

           //Act
           ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
           System.Threading.Thread.Sleep(1500);
           hostSettings.EnableModuleOnlineHelpCheckbox.Checked = true;
           hostSettings.UpdateLink.Click();
           System.Threading.Thread.Sleep(1000);
           ieInstance.GoTo(SiteURL + "/testpage.aspx");
           System.Threading.Thread.Sleep(1500);

           //Assert
           //modulePage.ModuleActionMenuImage.FireEvent("onmouseover");
           Assert.IsTrue(modulePage.ModuleOnlineHelpLink.Exists);
       }

       [Test]
       public void Change_Host_Skin()
       {
           //Arrange
           WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
           LoginPage loginPage = new LoginPage(homePage);
           loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
           System.Threading.Thread.Sleep(5000);
           ElementContainer<Element> header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));

           String minimalExtropyString;
           if (VersionType.CompareTo("Community") == 0)
           {
               minimalExtropyString = "Skins_MinimalExtropy_";
           }
           else
           {
               minimalExtropyString = "Skins_MinimalExtropyPro_";
           }

           Element stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropyString)))[0];
           Assert.IsTrue(stylesheet.Exists);
           Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
           ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/Default.aspx");
           ExtensionsPage extensionsPage = new ExtensionsPage(homePage);

           //Add a Skin to the site
           extensionsPage.InstallExtension(SkinPath);

           //Act
           ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
           HostSettingsPage hostSettings = new HostSettingsPage(homePage);
           hostSettings.HostSkinSelectList.Select(SkinUsed);
           hostSettings.HostEmailTextField.Value = "test@dnn.com";
           hostSettings.UpdateLink.Click();
           System.Threading.Thread.Sleep(1000);
           ieInstance.GoTo(SiteURL + "/Home.aspx");

           //Assert
           stylesheet = header.Elements.Filter(Find.ById(s => s.Contains("Skins_" + SkinName + "_")))[0];
           Assert.IsTrue(stylesheet.Exists);
           Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);

       }

       [Test]
       public void Change_Host_Container()
       {
           //Arrange
           WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
           LoginPage loginPage = new LoginPage(homePage);
           loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
           System.Threading.Thread.Sleep(5000);
           ElementContainer<Element> header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));

           String darkKnightString = "Containers_DarkKnight_";
           //if (VersionType.CompareTo("Community") == 0)
           //{
           //    minimalExtropyString = "Containers_MinimalExtropy_";
           //}
           //else
           //{
           //    minimalExtropyString = "Containers_MinimalExtropyPro_";
           //}

           Element stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(darkKnightString)))[0];
           Assert.IsTrue(stylesheet.Exists);
           Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
           ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/Default.aspx");
           ExtensionsPage extensionsPage = new ExtensionsPage(homePage);

           //Add a Skin to the site
           extensionsPage.InstallExtension(SkinPath);

           //Act
           ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
           HostSettingsPage hostSettings = new HostSettingsPage(homePage);
           hostSettings.HostContainerSelectList.Select(ContainerUsed);
           hostSettings.HostEmailTextField.Value = "test@dnn.com";
           hostSettings.UpdateLink.ClickNoWait();
           System.Threading.Thread.Sleep(1000);
           ieInstance.GoTo(SiteURL + "/Home.aspx");

           //Assert
           System.Threading.Thread.Sleep(1500);
           stylesheet = header.Elements.Filter(Find.ById(s => s.Contains("Containers_" + SkinName + "_")))[0];
           Assert.IsTrue(stylesheet.Exists);
           Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
       }

       [Test]
       public void Change_Edit_Skin()
       {
           //Arrange
           WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
           LoginPage loginPage = new LoginPage(homePage);
           loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
           System.Threading.Thread.Sleep(5000);
           ElementContainer<Element> header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));

           //Add a page to the website
           String pageName = "Test Page";
           ControlPanel controlPanel = null;
           RibbonBar ribbonBar = null;
           bool usesRibbonBar = false;

           if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
           {
               ribbonBar = new RibbonBar(homePage);
               ribbonBar.NewPageLink.Click();
               usesRibbonBar = true;
           }
           else
           {
               controlPanel = new ControlPanel(homePage);
               controlPanel.AddPageLink.Click();
           }
           PageSettingsPage newPage = new PageSettingsPage(homePage);
           newPage.PageNameField.Value = pageName;
           newPage.PageTemplateSelect.Select("None Specified");
           newPage.AllUsersViewPermissionCheckbox.ClickNoWait();
           newPage.AddPageLink.ClickNoWait();
           System.Threading.Thread.Sleep(2000);
           ieInstance.GoTo(SiteURL + "/testpage.aspx");
           //Add an HTML module to the page
           string moduleContent = "This is a test module. ";
           if (!usesRibbonBar)
           {
               if (VersionType.CompareTo("Community") == 0)
               {
                   controlPanel.AddHTMLModuleToPageWithContent("Test Module", "HTML", moduleContent, 0);
               }
               else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
               {
                   controlPanel.AddHTMLModuleToPageWithContent("Test Module", "HTML Pro", moduleContent, 0);
               }
           }
           else
           {
               if (VersionType.CompareTo("Community") == 0)
               {
                   ribbonBar.AddHTMLModuleToPageWithContent("Test Module", "HTML", moduleContent, 0);

               }
               else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
               {
                   ribbonBar.AddHTMLModuleToPageWithContent("Test Module", "HTML Pro", moduleContent, 0);

               }
           }


           ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/Default.aspx");
           ExtensionsPage extensionsPage = new ExtensionsPage(homePage);

           //Add a Skin to the site
           extensionsPage.InstallExtension(SkinPath);

           //Act
           ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
           HostSettingsPage hostSettings = new HostSettingsPage(homePage);
           hostSettings.EditSkinSelectList.Select(SkinUsed);
           hostSettings.HostEmailTextField.Value = "test@dnn.com";
           hostSettings.UpdateLink.Click();
           System.Threading.Thread.Sleep(1000);
           ieInstance.GoTo(SiteURL + "/testpage.aspx");

           //Assert
           String minimalExtropyString;
           if (VersionType.CompareTo("Community") == 0)
           {
               minimalExtropyString = "Skins_MinimalExtropy_";
           }
           else
           {
               minimalExtropyString = "Skins_MinimalExtropyPro_";
           }

           Element stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropyString)))[0];
           Assert.IsTrue(stylesheet.Exists);
           Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
           ModulePage modulePage = new ModulePage(homePage);
           modulePage.GetEditModuleContentLink(0).Click();
           stylesheet = header.Elements.Filter(Find.ById(s => s.Contains("Skins_" + SkinName + "_")))[0];
           Assert.IsTrue(stylesheet.Exists);
           Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);

       }

       [Test]
       public void Change_Edit_Container()
       {
           //Arrange
           WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
           LoginPage loginPage = new LoginPage(homePage);
           loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
           System.Threading.Thread.Sleep(5000);
           ElementContainer<Element> header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
           ElementContainer<Element> popUpHeader;
           

           //Add a page to the website
           String pageName = "Test Page";
           ControlPanel controlPanel = null;
           RibbonBar ribbonBar = null;
           bool usesRibbonBar = false;

           if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
           {
               ribbonBar = new RibbonBar(homePage);
               ribbonBar.NewPageLink.Click();
               usesRibbonBar = true;
           }
           else
           {
               controlPanel = new ControlPanel(homePage);
               controlPanel.AddPageLink.Click();
           }
           PageSettingsPage newPage = new PageSettingsPage(homePage);
           newPage.PageNameField.Value = pageName;
           newPage.PageTemplateSelect.Select("None Specified");
           newPage.AllUsersViewPermissionCheckbox.Click();
           newPage.AddPageLink.ClickNoWait();
           System.Threading.Thread.Sleep(2000);
           ieInstance.GoTo(SiteURL + "/testpage.aspx");
           //Add an HTML module to the page
           string moduleContent = "This is a test module. ";
           if (!usesRibbonBar)
           {
               if (VersionType.CompareTo("Community") == 0)
               {
                   controlPanel.AddHTMLModuleToPageWithContent("Test Module", "HTML", moduleContent, 0);
               }
               else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
               {
                   controlPanel.AddHTMLModuleToPageWithContent("Test Module", "HTML Pro", moduleContent, 0);
               }
           }
           else
           {
               if (VersionType.CompareTo("Community") == 0)
               {
                   ribbonBar.AddHTMLModuleToPageWithContent("Test Module", "HTML", moduleContent, 0);

               }
               else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
               {
                   ribbonBar.AddHTMLModuleToPageWithContent("Test Module", "HTML Pro", moduleContent, 0);

               }
           }


           System.Threading.Thread.Sleep(1500);
           ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/Default.aspx");
           ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
           System.Threading.Thread.Sleep(1500);

           //Add a Skin to the site
           extensionsPage.InstallExtension(SkinPath);

           //Act
           ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
           HostSettingsPage hostSettings = new HostSettingsPage(homePage);
           hostSettings.EditContainerSelectList.Select(ContainerUsed);
           hostSettings.HostEmailTextField.Value = "test@dnn.com";
           hostSettings.UpdateLink.Click();
           System.Threading.Thread.Sleep(1000);
           ieInstance.GoTo(SiteURL + "/testpage.aspx");

           //Assert
           String minimalExtropyString;
           if (VersionType.CompareTo("Community") == 0)
           {
               minimalExtropyString = "Containers_DarkKnight_";
           }
           else
           {
               minimalExtropyString = "Containers_DarkKnight_";
           }

           Element stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropyString)))[0];
           Assert.IsTrue(stylesheet.Exists);
           Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
           ModulePage modulePage = new ModulePage(homePage);
           modulePage.GetEditModuleContentLink(0).Click();
           if (homePage.PopUpFrame != null)
           {
               popUpHeader = (ElementContainer<Element>)homePage.PopUpFrame.Element(Find.ById("Head"));
           }
           else
           {
               popUpHeader = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
           }
           stylesheet = popUpHeader.Elements.Filter(Find.ById(s => s.Contains("Containers_" + SkinName + "_")))[0];
           Assert.IsTrue(stylesheet.Exists);
           Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);

       }



        //[Test]
        //public void Enabling_Disabling_Copyright_Credits()
        //{
        //    //Arrange
        //    WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
        //    //Assert
        //    Assert.AreEqual("<!-- Copyright (c) 2002-2009", homePage.Header.Text);
        //    Assert.AreEqual("<!-- by DotNetNuke Corporation", homePage.Header.Text);

        //    //Arrange
        //    LoginPage loginPage = new LoginPage(homePage);
        //    loginPage.LoginLink.Click();

        //    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
        //    ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
        //    HostSettingsPage hostSettings = new HostSettingsPage(homePage);

        //    //Act
        //    hostSettings.HostEmailTextField.TypeText("test@dnn.com");
        //    hostSettings.UpdateLink.Click();
        //    System.Threading.Thread.Sleep(2000);
        //    hostSettings.EnableCopyrightCheckbox.Checked = false;
        //    hostSettings.UpdateLink.Click();

        //    //Assert
        //    Assert.AreNotEqual("<!-- Copyright (c) 2002-2009", homePage.Header.Text);
        //    Assert.AreNotEqual("<!-- by DotNetNuke Corporation", homePage.Header.Text);
        //}

        #endregion

        #region Public Methods


       

        #endregion

    }

}

